/*
 *  AllocatedObject.h
 *  RTDemo
 *
 *  Created by steveca  on 13/05/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef __ALLOCATED_OBJECT_H__
#define __ALLOCATED_OBJECT_H__

#include <iostream>
#include "NedAllocPolicy.h"

namespace Sdlfw {
	
	template <class AllocPolicy>
	class AllocatedObject
        {
        public:
            explicit AllocatedObject() {}
            ~AllocatedObject() {}
            
            void *operator new (size_t size)
            {
                std :: cout << "Overloaded operator new" << std :: endl;
                return AllocPolicy :: allocateBytes(size); 
            }
            
            void *operator new (size_t size, const char *file, int line, const char *func)
            {
                
                std :: cout << "Overloaded operator new" << std :: endl;
                std :: cout << "File: " << file << std :: endl;
                std :: cout << "Line: " << line << std :: endl;
                std :: cout << "Function: " << func << std :: endl; 
                return AllocPolicy :: allocateBytes(size, file, line, func); 
            }
            
            void *operator new (size_t size, void *ptr)
            {
                return ptr;
            }
            
            void operator delete (void *ptr)
            {
                std :: cout << "Overloaded operator delete" << std :: endl;
                AllocPolicy :: deallocateBytes(ptr);
            }
            
        };
	
	
	class MyObject : public AllocatedObject<NedAllocPolicy>
	{
	public:
		MyObject() 
		{
			std :: cout << "MyObject -- Constructor" << std :: endl;
			//memcpy(m_data,'\0',1024);
			m_string = new char[1024];
		}
		
		int getInt()
		{
			return 10;
		}
		
		~MyObject()
		{
			std :: cout << "MyObject -- Destructor" << std :: endl;
			delete[] m_string;
		}
		
	private:
		char *m_string;
	};
}


#endif